from ast import Return
from dataclasses import fields
from tkinter import W
from turtle import textinput
from django import forms
from django.http import HttpResponse
from app01 import models
from django.core.validators import RegexValidator
from django.shortcuts import render

# Create your views here.


def index(request):
    return render(request, 'app01/index.html')


class RegisterModelForm(forms.ModelForm):
    mobile_phone = forms.CharField(label='手机号',
                                   validators=[RegexValidator(r'^(1[3|4|5|6|7|8|9])\d{9}$', '手机号格式错误'), ])
    password = forms.CharField(label='密码', widget=forms.PasswordInput())
    comfirm_password = forms.CharField(label='确认密码', widget=forms.PasswordInput())

    # attrs={'class': 'form-control', 'placeholder': '请输入确认密码'})
    code = forms.CharField(label='验证码', widget=forms.TextInput())

    class Meta:
        model = models.UserInfo
        # fields = ['username', 'password', 'comfirmpassword',
        #           'email', 'mobile_phone','code' ]
        fields = ['username', 'email', 'password', 'comfirm_password', 'mobile_phone', 'code']
        # fields = "__all__"
        # ['username', 'email', 'password', 'comfirm_password', 'mobile_phone']

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        for name, field in self.fields.items():
            print(name)
            field.widget.attrs['class'] = 'form-control'
            field.widget.attrs['placeholder'] = '请输入%s' % (field.label)


def register(request):
    form = RegisterModelForm()
    return render(request, 'app01/register.html', {'form': form})

def send_sms(request):
    print(request.GET)
    return HttpResponse('成功')
    